<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed to Jasig under one or more contributor license
    agreements. See the NOTICE file distributed with this work
    for additional information regarding copyright ownership.
    Jasig licenses this file to you under the Apache License,
    Version 2.0 (the "License"); you may not use this file
    except in compliance with the License.  You may obtain a
    copy of the License at the following location:

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:webflow="http://www.springframework.org/schema/webflow-config"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd">

  <import resource="spring-configuration/propertyFileConfigurer.xml"/>

  <!-- Theme Resolver -->
  <bean id="themeResolver" class="org.jasig.cas.services.web.ServiceThemeResolver"
        p:defaultThemeName="${cas.themeResolver.defaultThemeName}"
        p:argumentExtractors-ref="argumentExtractors"
        p:servicesManager-ref="servicesManager">
    <property name="mobileBrowsers">
      <map>
        <entry key=".*iPhone.*" value="iphone"/>
        <entry key=".*Android.*" value="iphone"/>
        <entry key=".*Safari.*Pre.*" value="iphone"/>
        <entry key=".*Nokia.*AppleWebKit.*" value="iphone"/>
      </map>
    </property>
  </bean>

  <!-- View Resolver -->
  <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
        p:order="0">
    <property name="basenames">
      <list>
        <value>${cas.viewResolver.basename}</value>
        <value>protocol_views</value>
      </list>
    </property>
  </bean>

  <bean id="xmlViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver" 
  		p:order="1" 
  		p:location="/WEB-INF/view/views.xml" 
  />
  
  <!-- Locale Resolver -->
  <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>

  <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>

  <bean id="urlBasedViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"
        p:viewClass="org.springframework.web.servlet.view.InternalResourceView"
        p:prefix="/WEB-INF/view/jsp/"
        p:suffix=".jsp"
        p:order="2"/>
  
  <bean id="errorHandlerResolver" class="org.jasig.cas.web.FlowExecutionExceptionResolver"/>

  <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>

  <bean
      id="handlerMappingC"
      class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
      <props>
        <prop key="/logout">logoutController</prop>
        <prop key="/serviceValidate">serviceValidateController</prop>
        <prop key="/validate">legacyValidateController</prop>
        <prop key="/proxy">proxyController</prop>
        <prop key="/proxyValidate">proxyValidateController</prop>
        <prop key="/samlValidate">samlValidateController</prop>
        <prop key="/services/add.html">addRegisteredServiceSimpleFormController</prop>
        <prop key="/services/edit.html">editRegisteredServiceSimpleFormController</prop>
        <prop key="/services/loggedOut.html">serviceLogoutViewController</prop>
        <prop key="/services/viewStatistics.html">viewStatisticsController</prop>
        <prop key="/services/*">manageRegisteredServicesMultiActionController</prop>
        <prop key="/openid/*">openIdProviderController</prop>
        <prop key="/authorizationFailure.html">passThroughController</prop>
        <prop key="/403.html">passThroughController</prop>
        <prop key="/status">healthCheckController</prop>
      </props>
    </property>
    <property
        name="alwaysUseFullPath" value="true"/>
    <!--
     uncomment this to enable sending PageRequest events.
     <property
       name="interceptors">
       <list>
         <ref bean="pageRequestHandlerInterceptorAdapter" />
       </list>
     </property>
      -->
  </bean>

  <bean id="passThroughController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>

  <bean
      id="openIdProviderController"
      class="org.jasig.cas.web.OpenIdProviderController"
      p:loginUrl="${cas.securityContext.casProcessingFilterEntryPoint.loginUrl}"/>

  <bean
      id="serviceLogoutViewController"
      class="org.springframework.web.servlet.mvc.ParameterizableViewController"
      p:viewName="serviceLogoutView"/>

  <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping" p:flowRegistry-ref="flowRegistry"
        p:order="2">
    <property name="interceptors">
      <ref local="localeChangeInterceptor"/>
    </property>
  </bean>


  <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"
        p:flowExecutor-ref="flowExecutor"
        p:flowUrlHandler-ref="flowUrlHandler"/>

  <bean id="flowUrlHandler" class="org.jasig.cas.web.flow.CasDefaultFlowUrlHandler"/>

  <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
    <webflow:flow-execution-attributes>
      <webflow:always-redirect-on-pause value="false"/>
      <webflow:redirect-in-same-state value="false" />
    </webflow:flow-execution-attributes>
    <webflow:flow-execution-listeners>
      <webflow:listener ref="terminateWebSessionListener" />
    </webflow:flow-execution-listeners>
  </webflow:flow-executor>

  <webflow:flow-registry id="flowRegistry" flow-builder-services="builder">
    <webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login"/>
  </webflow:flow-registry>

  <webflow:flow-builder-services id="builder" view-factory-creator="viewFactoryCreator"
                                 expression-parser="expressionParser"/>

  <bean id="terminateWebSessionListener" class="org.jasig.cas.web.flow.TerminateWebSessionListener"
      p:serviceManagerUrl="${cas.securityContext.serviceProperties.service}" />

  <bean id="expressionParser" class="org.springframework.webflow.expression.WebFlowOgnlExpressionParser"/>

  <bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers">
      <list>
        <ref local="viewResolver"/>
      </list>
    </property>
  </bean>
  <bean id="proxyValidateController" class="org.jasig.cas.web.ServiceValidateController"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:proxyHandler-ref="proxy20Handler"
        p:argumentExtractor-ref="casArgumentExtractor"/>

  <bean id="serviceValidateController" class="org.jasig.cas.web.ServiceValidateController"
        p:validationSpecificationClass="org.jasig.cas.validation.Cas20WithoutProxyingValidationSpecification"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:proxyHandler-ref="proxy20Handler"
        p:argumentExtractor-ref="casArgumentExtractor"/>

  <bean id="samlValidateController" class="org.jasig.cas.web.ServiceValidateController"
        p:validationSpecificationClass="org.jasig.cas.validation.Cas20WithoutProxyingValidationSpecification"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:proxyHandler-ref="proxy20Handler"
        p:argumentExtractor-ref="samlArgumentExtractor"
        p:successView="casSamlServiceSuccessView"
        p:failureView="casSamlServiceFailureView"/>

  <bean id="legacyValidateController" class="org.jasig.cas.web.ServiceValidateController"
        p:proxyHandler-ref="proxy10Handler"
        p:successView="cas1ServiceSuccessView"
        p:failureView="cas1ServiceFailureView"
        p:validationSpecificationClass="org.jasig.cas.validation.Cas10ProtocolValidationSpecification"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:argumentExtractor-ref="casArgumentExtractor"/>

  <bean id="proxyController" class="org.jasig.cas.web.ProxyController"
        p:centralAuthenticationService-ref="centralAuthenticationService"/>

  <bean id="viewStatisticsController" class="org.jasig.cas.web.StatisticsController"
        p:casTicketSuffix="${host.name}">
    <constructor-arg index="0" ref="ticketRegistry"/>
  </bean>

  <bean id="logoutController" class="org.jasig.cas.web.LogoutController"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:logoutView="casLogoutView"
        p:warnCookieGenerator-ref="warnCookieGenerator"
        p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"
        p:servicesManager-ref="servicesManager"
        p:followServiceRedirects="${cas.logout.followServiceRedirects:false}"/>

  <bean id="healthCheckController" class="org.jasig.cas.web.HealthCheckController"
        p:healthCheckMonitor-ref="healthCheckMonitor"/>

  <bean id="initialFlowSetupAction" class="org.jasig.cas.web.flow.InitialFlowSetupAction"
        p:argumentExtractors-ref="argumentExtractors"
        p:warnCookieGenerator-ref="warnCookieGenerator"
        p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"/>

  <bean id="authenticationViaFormAction" class="org.jasig.cas.web.flow.AuthenticationViaFormAction"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:warnCookieGenerator-ref="warnCookieGenerator"/>

  <bean id="generateServiceTicketAction" class="org.jasig.cas.web.flow.GenerateServiceTicketAction"
        p:centralAuthenticationService-ref="centralAuthenticationService"/>

  <bean id="sendTicketGrantingTicketAction" class="org.jasig.cas.web.flow.SendTicketGrantingTicketAction"
        p:centralAuthenticationService-ref="centralAuthenticationService"
        p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"/>

  <bean id="gatewayServicesManagementCheck" class="org.jasig.cas.web.flow.GatewayServicesManagementCheck">
    <constructor-arg index="0" ref="servicesManager"/>
  </bean>

  <bean id="serviceAuthorizationCheck" class="org.jasig.cas.web.flow.ServiceAuthorizationCheck">
        <constructor-arg index="0" ref="servicesManager"/>
  </bean>

  <bean id="generateLoginTicketAction" class="org.jasig.cas.web.flow.GenerateLoginTicketAction"
        p:ticketIdGenerator-ref="loginTicketUniqueIdGenerator"/>

  <bean id="addRegisteredServiceSimpleFormController"
        class="org.jasig.cas.services.web.RegisteredServiceSimpleFormController"
        p:formView="addServiceView"
        p:successView="addServiceView"
        p:commandName="registeredService"
        p:validator-ref="registeredServiceValidator"
        p:sessionForm="true">
    <constructor-arg index="0" ref="servicesManager"/>
    <constructor-arg index="1" ref="attributeRepository"/>
  </bean>

  <bean id="editRegisteredServiceSimpleFormController"
        class="org.jasig.cas.services.web.RegisteredServiceSimpleFormController"
        p:formView="editServiceView"
        p:successView="editServiceView"
        p:commandName="registeredService"
        p:validator-ref="registeredServiceValidator"
        p:sessionForm="false">
    <constructor-arg index="0" ref="servicesManager"/>
    <constructor-arg index="1" ref="attributeRepository"/>
  </bean>

  <bean id="registeredServiceValidator" class="org.jasig.cas.services.web.support.RegisteredServiceValidator"
        p:servicesManager-ref="servicesManager" 
        p:personAttributeDao-ref="attributeRepository" />

  <bean id="manageRegisteredServicesMultiActionController"
        class="org.jasig.cas.services.web.ManageRegisteredServicesMultiActionController">
    <constructor-arg index="0" ref="servicesManager"/>
    <constructor-arg index="1" value="${cas.securityContext.serviceProperties.service}"/>
  </bean>

  <bean id="messageInterpolator" class="org.jasig.cas.util.SpringAwareMessageMessageInterpolator"/>

  <bean id="credentialsValidator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"
        p:messageInterpolator-ref="messageInterpolator"/>
</beans>